﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MouldingAndMillwork.SSIS
{
    public partial class SSISUtility
    {
        #region CLASS: EnumEx
        public class EnumEx
        {
            #region Static Public Methods
            public static string GetEnumName(System.Type enumType)
            {
                return enumType.Name.Replace('_', ' ');
            }

            public static string[] GetNames(System.Type enumType)
            {
                string[] enumNamesUnderscored = Enum.GetNames(enumType);
                string[] enumNamesSpaced = new string[enumNamesUnderscored.Length];

                for (int index = 0; index < enumNamesUnderscored.Length; index++)
                {
                    enumNamesSpaced[index] = enumNamesUnderscored[index].Replace('_', ' ');
                }

                return enumNamesSpaced;
            }

            public static string GetName(object enumValue)
            {
                if (enumValue is Enum)
                {
                    return enumValue.ToString().Replace('_', ' ');
                }
                else
                {
                    throw new ArgumentException("Non-enum passed to GetName", "enumValue");
                }
            }

            public static Array ParseArray(System.Type enumType, string[] stringValues)
            {
                int stringValuesLength = 0;
                if (stringValues != null)
                {
                    stringValuesLength = stringValues.Length;
                }
                object[] enumValues = new object[stringValuesLength];
                for (int index = 0; index < enumValues.Length; index++)
                {
                    enumValues[index] = Enum.Parse(enumType, stringValues[index].Replace(' ', '_'));
                }

                return enumValues;
            }

            public static object Parse(System.Type enumType, string stringValue)
            {
                return Enum.Parse(enumType, stringValue.Replace(' ', '_'));
            }
            #endregion
        }
        #endregion
    }
}
